package com.prig.base.service;

import com.prig.base.entity.AdminRoleRelation;
import com.prig.base.entity.AdminRoleRelationId;
import com.prig.base.repository.AdminRoleRelationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminRoleService {
    private AdminRoleRelationRepository adminRoleRelationRepository;
    @Autowired
    public void setAdminRoleRelationRepository(AdminRoleRelationRepository adminRoleRelationRepository) {
        this.adminRoleRelationRepository = adminRoleRelationRepository;
    }
    public AdminRoleRelation add(AdminRoleRelationId id){
        AdminRoleRelation adminRoleRelation = new AdminRoleRelation(id);
        return adminRoleRelationRepository.save(adminRoleRelation);
    }
    public void delete(AdminRoleRelationId id){
        AdminRoleRelation adminRoleRelation = new AdminRoleRelation(id);
        adminRoleRelationRepository.delete(adminRoleRelation);
    }

    public void delete(long adminId) {
        adminRoleRelationRepository.deleteByAdminId(adminId);
    }

    public void add(List<AdminRoleRelationId> adminRoleRelationIdList){
        adminRoleRelationIdList.forEach(a->add(a));
    }
}
